package com.example.facedemo

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.baidu.aip.FaceDetectActivity
import com.baidu.aip.MainFaceDecActivity
import com.baidu.aip.face.camera.ICameraControl
import com.bumptech.glide.Glide
import com.example.facedemo.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {
    private lateinit var bind: ActivityMainBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        bind = ActivityMainBinding.inflate(layoutInflater)
        setContentView(bind.root)
        initView()
    }

    private fun initView() {
        bind.ivImage.setOnClickListener {
            val intent = Intent(this, MainFaceDecActivity::class.java)
            intent.putExtra("cameraFacing",ICameraControl.CAMERA_FACING_BACK)
            startActivityForResult(intent, 200)
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == 200) {
            if (resultCode == RESULT_OK) {
                var image = data!!.getByteArrayExtra("data")
                Glide.with(this).load(image).into(bind.ivImage)
            }
        }
    }
}